package cn.mengfly.testnrz.util;

import cn.mengfly.testnrz.crazyIm.ServerConstants;

public class ZookeeperUtil {

    public static long getId(String nodePath, String prefix) {
        String sid = null;
        if (null == nodePath) {
            throw new RuntimeException("节点注册失败");
        }
        int index = nodePath.lastIndexOf(ServerConstants.PATH_PREFIX);
        if (index > 0) {
            index += prefix.length();
            sid = index < nodePath.length() ? nodePath.substring(index) : null;
        }
        if (null == sid) {
            throw new RuntimeException("节点ID生成失败");
        }
        return Long.parseLong(sid);
    }
}
